var express = require("express");
var router = express.Router();
const Result = require("../utils/result");
const messageService = require("../services/message");

//获取消息列表
router.get('/list',async function (req, res){
    const {userId,size,page} = req.query;
    const {rows,count} = await messageService.getList(userId,size,page);
    res.json(Result.success( {  messages:rows, count }))
})

//获取未读消息数量
router.get('/readNum',async function (req, res){
    const {userId} = req.query;
    const count = await messageService.getReadNum(userId);
    res.json(Result.success( { count }))
});

//将未读消息变成已读
router.get('/readed',async function (req, res){
    const {userId} = req.query;
    await messageService.readed(userId);
    res.json(Result.success());
});

module.exports = router;
